<template>
  <div class="MenuBox">
    <el-menu
      :router="true"
      :unique-opened="true"
      active-text-color="#333333"
      class="noCopy menu"
      ref="elMenuRef"
    >
      <template v-for="(firstItem, firstIndex) in menuList">
        <el-menu-item :index="firstItem.path" :key="firstIndex">
          <svg-icon class="mr10" :icon-class="firstItem.icon" />
          <span>{{ firstItem.label }}</span>
        </el-menu-item>
      </template>
      <el-submenu index="1">
        <template slot="title">
          <!-- <i class="el-icon-location"></i> -->
          <svg-icon class="mr10" icon-class="home" /> <span>个人中心</span>
        </template>
        <el-menu-item @click="changePwd">
          <span>修改密码</span>
        </el-menu-item>
        <el-menu-item @click="outLogin">
          <span>退出</span>
        </el-menu-item>
      </el-submenu>

      <!-- <editEmail ref="emailEdit"></editEmail> -->
      <editPwd ref="editPwd"></editPwd>
    </el-menu>
    <!-- <div class="welcome">
      <svg-icon icon-class="smile" size="26" />
      <span class="ml10">欢迎您，{{ userInfo.name }}！</span>
    </div> -->
  </div>
</template>

<script>
import { mapMutations } from "vuex";
// import editEmail from "@/components/editEmail_dialog.vue";
import editPwd from "@/components/editPwd_dialog.vue";
export default {
  data() {
    return {
      menuList: [
        { label: "用户列表", path: "/user", icon: "user" },
        { label: "整改列表", path: "/change", icon: "change" },
        // { label: "数据备份", path: "/putOnRecords", icon: "putOnRecords" },
      ],
    };
  },
  components: {
    // editEmail,
    editPwd,
  },
  computed: {
    userInfo() {
      return { ...this.$store.state.user };
    },
  },
  mounted() {},
  methods: {
    ...mapMutations({
      setToken: "setToken",
      delUser: "delUser",
    }),
    changePwd() {
      this.$refs.editPwd.showDialog();
    },
    outLogin() {
      this.$alert("确认退出登录？", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      }).then(() => {
        this.$cookies.remove("token");
        this.$cookies.remove("cookiesAdminUser");

        this.setToken("");
        this.delUser();
        this.$message({
          type: "success",
          message: "退出成功!",
        });
        setTimeout(() => {
          this.$router.push({
            path: "/login",
          });
        }, 1000);
      });
    },
  },
};
</script>

<style lang="less" scoped>
.MenuBox {
  background: #fff;
  height: 100%;
  overflow-x: hidden;
  ::-webkit-scrollbar {
    display: none;
  }
  .menu {
    height: 90%;
    padding-bottom: 20px;
    border-right: none;
    overflow: auto;

    /deep/ .el-submenu__title,
    .el-menu-item {
      font-size: 16px;
    }
    /deep/.is-opened {
      .el-submenu__title {
        background: #dce9ff;
      }
      .el-menu {
        background: #f2f7ff;

        .el-menu-item {
          color: #a0a0a0;
        }
      }
    }
  }

  .welcome {
    width: 100%;
    font-weight: 600;

    display: flex;
    align-items: center;
    // text-align: center;
    padding-left: 20px;
    // border: 1px solid green;
  }
  .menu-itemCount {
    width: 18px;
    display: inline-block;
    height: 18px;
    line-height: 18px;
    margin-left: 10px;
    border-radius: 16px;
    background: #df3737;
    text-align: center;
    font-size: 12px;
    color: #fff;
    // padding: 3px;
  }
}
</style>
